﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace PacManBoardControl
{
    /// <summary>
    /// Helps animate a player from a start position to an
    /// end position.
    /// </summary>
    class PositionAnimator
    {
        #region Public methods and properties

        /// <summary>
        /// Constructor.
        /// </summary>
        public PositionAnimator(Point startPosition, Point endPosition)
        {
            StartPosition = startPosition;
            EndPosition = endPosition;
        }

        /// <summary>
        /// Gets or sets the starting position for the animation.
        /// </summary>
        public Point StartPosition { get; set; }

        /// <summary>
        /// Gets or sets the end position for the animation.
        /// </summary>
        public Point EndPosition { get; set; }

        /// <summary>
        /// Returns the position for the time-fraction passed in.
        /// The time fraction is a number between 0.0 - 1.0
        /// </summary>
        public Point getPosition(double timeFraction)
        {
            int diffX = EndPosition.X - StartPosition.X;
            int diffY = EndPosition.Y - StartPosition.Y;
            if (Math.Abs(diffX) > 30 || Math.Abs(diffY) > 30)
            {
                // This is a large jump. It could be a journey through 
                // the "tunnel" or a ghost or Pac-Man respawning. 
                // In these cases we just go staright to the destination.
                return EndPosition;
            }
            else
            {
                // It is a small movement, so we animate it...
                int currentX = (int)(StartPosition.X + diffX * timeFraction);
                int currentY = (int)(StartPosition.Y + diffY * timeFraction);
                return new Point(currentX, currentY);
            }
        }

        #endregion

    }
}
